const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');

const Role = sequelize.define('Role', {
  id: {
    type: DataTypes.UUID,
    defaultValue: DataTypes.UUIDV4,
    primaryKey: true
  },
  name: {
    type: DataTypes.STRING,
    allowNull: false,
    unique: true,
    comment: '角色名称'
  },
  description: {
    type: DataTypes.TEXT,
    comment: '角色描述'
  },
  permissions: {
    type: DataTypes.JSON,
    defaultValue: [],
    comment: '角色权限'
  },
  isSystem: {
    type: DataTypes.BOOLEAN,
    defaultValue: false,
    comment: '是否为系统角色'
  },
  status: {
    type: DataTypes.ENUM('active', 'inactive'),
    defaultValue: 'active',
    comment: '角色状态'
  }
}, {
  indexes: [
    {
      unique: true,
      fields: ['name'],
      comment: '角色名称索引'
    }
  ],
  comment: '角色信息表'
});

module.exports = Role; 